package dmt16.TelemetrySuit.Controller.SensorTypes
{
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class ElectroLycraSensor implements ISensorType
	{
		public function ElectroLycraSensor()
		{
		}
		
		public function get sensorType():int
		{
			return SensorType.ELECTRO_LYCRA;
		}
		
		public function get dataFormat():int
		{
			return DataFormat.UInt16;
		}
		
		private var average:Number=0;
		
		private function _convertToAngle(value:Number):Number{
			return average*0.9+0.1*((value-250)*Math.PI/90+Math.PI/2);
		}
		
		public function addData(value:*, time:Number):void
		{
			var raw_val:Number=value as Number;
			_data.push(_convertToAngle(raw_val));
			dispatchEvent(new SensorEvent(SensorEvent.SENSOR_DATA_EVENT));
		}
		
		private var _data:Vector.<Number>=new Vector.<Number>();
		public function get data():Vector.<Number>{
			return _data;
		}
		
		private var _eventManager:EventDispatcher=new EventDispatcher();
		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
		{
			_eventManager.addEventListener(type,listener,useCapture,priority,useWeakReference);
		}
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void{
			_eventManager.removeEventListener(type,listener,useCapture);
		}
		public function dispatchEvent(event:Event):Boolean{
			return _eventManager.dispatchEvent(event);
		}
		public function hasEventListener(type:String):Boolean{
			return _eventManager.hasEventListener(type);
		}
		public function willTrigger(type:String):Boolean{
			return _eventManager.willTrigger(type);
		}
	}
}